import { request } from '@/utils/request'

/**
 * 提交预约
 * @param {*} params  预约信息
 * @returns
 */
export function addAppointment(params) {
  return request({
    url: '/sys/appointment/addAppointment',
    method: 'post',
    data: params
  })
}

/**
 * 获取医生可预约时间
 * @param {*} date
 * @param {*} doctorId
 * @returns
 */
export function fetchAvailableTimes(date, doctorId) {
  return request.get('/sys/appointment/availableTime', {
    params: { date, doctorId }
  })
}

/**
 * 获取医生列表
 * @returns
 */
export function getDoctorList() {
  return request({
    url: '/sys/appointment/doctorList',
    method: 'get'
  })
}

/**
 * 获取预约列表
 * @param {*} params
 * @returns
 */
export function getAppointmentPageList(params) {
  return request({
    url: '/sys/appointment/pageList',
    method: 'post',
    data: params
  })
}

/**
 * 修改预约
 * @param {*} params
 * @returns
 */
export function updateAppointment(params) {
  return request({
    url: '/sys/appointment/updateAppointment',
    method: 'post',
    data: params
  })
}

export function appointmentCancel(id, start) {
  return request.delete('/app/reservation/updateStatus', {
    params: {
      reservationId: id,
      status: start
    }
  })
}

/**
 * 查询医生患者预约信息
 * @param {string|null} datatime - 查询日期，格式 yyyy-MM-dd
 * @returns {Promise}
 */
export function queryDoctorPatient(datatime) {
  // 3. 使用 URLSearchParams 构建查询参数（更优雅）
  const params = new URLSearchParams({
    appointmentTime: datatime
  })

  return request.get(`/sys/appointment/specifyDoctor?${params.toString()}`)
}
